<?php 
function __autoload($class_name) {
		include $class_name . '.php';
	}
class Construct {
	const NO_PARAM = "NO_CONST";
	const DB_PARAM = "DB_CONST";
}

class RLProject {
	//  Region:  DB / DB Fields
		const __TBL = "Project";
		const __FLD_PROJECT_ID = "PROJECT_ID";
		const __FLD_PROJECT_NAME = "PROJECT_NAME";
	//  Region:  DB / DB Fields End

	//  Region:  Properties
		public $projectId;
		public $projectName;
		public $isLoaded;
	//  Region:  Properties End

	function RLProject($projectId) {
		$conn = App::getDB();
		if($projectId != null) {
			// Populate from DB
			$this->populate($projectId);
		}
	}
	
	private function populate($projectId) {
		$qString = mysql_query("SELECT * FROM ". self::__TBL ." WHERE " . self::__FLD_PROJECT_ID . " = '" . $projectId . "'") or die(mysql_error());
			
		$row = mysql_fetch_array($qString);
		print_r(mysql_fetch_array($qString));
		$this->projectId = $row[self::__FLD_PROJECT_ID];
		$this->projectName = $row[self::__FLD_PROJECT_NAME];
		
		$this->isLoaded = true;
	}
	
	public function save() {
		if ($this->isLoaded === true) {
			$fieldValues = self::__FLD_PROJECT_ID . " = '" . mysql_real_escape_string($this->projectId) . "', ";
			$fieldValues .= self::__FLD_PROJECT_NAME . " = '" . mysql_real_escape_string($this->projectName) . "', ";
	
			$sql = "UPDATE " . self::__TBL . " SET  " . $fieldValues . " WHERE " . self::__FLD_PROJECT_ID . " = '" . $this->projectId . "'";
		} else {
			$fieldValues = "(";
			$fieldValues = self::__FLD_PROJECT_ID . " = '', ";
			$fieldValues .= self::__FLD_PROJECT_NAME . " = '" . mysql_real_escape_string($this->projectName) . "', ";
			$fieldValues .= ")";
		
			$fieldValues = str_replace("', )", "')", $fieldValues);
		
			$sql = "INSERT INTO " . self::__TBL . " VALUES " . $fieldValues;
		}
		
		print $sql . "<br>";
		
		$q = mysql_query($sql) or die(mysql_error());
		if($q)
			return true;
		else
			return false;
	}
	
	public function delete() {
		
	}
	
}

$test = new RLProject(null);
$test->projectName = "test13254359435u0";
$test->save();


?>